Option Explicit On
Option Strict On

Imports System.Collections
Imports nstl
Imports System.Collections.Generic
Imports nstl.Iterators
Imports NStl.SyntaxHelper


Namespace nstl.test
    Friend Class TestUtil
        Public Shared Function mismatch(Of T As IComparable(Of T))(ByVal _First1 As IInputIterator(Of T), ByVal _Last1 As IInputIterator(Of T), ByVal _First2 As IForwardIterator(Of T), ByVal _Last2 As IForwardIterator(Of T)) As Boolean
            Dim res As KeyValuePair(Of IInputIterator(Of T), IInputIterator(Of T)) = _
                Algorithm.Mismatch(Of T, IInputIterator(Of T), IInputIterator(Of T))(_First1, _Last1, _First2)
            Return Not ((res.Key.Equals(_Last1)) And (res.Value.Equals(_Last2)))
        End Function
        Public Shared Function mismatch(Of T As IComparable(Of T))(ByVal v1 As Vector(Of T), ByVal v2 As Vector(Of T)) As Boolean
            Return mismatch(v1.Begin, v1.End, v2.Begin, v2.End)
        End Function
        Public Shared Function mismatch(Of T As IComparable(Of T))(ByVal v1 As DList(Of T), ByVal v2 As Vector(Of T)) As Boolean
            Return mismatch(v1.Begin, v1.End, v2.Begin, v2.End)
        End Function
        Public Shared Function mismatch(Of T As IComparable(Of T))(ByVal v1 As Vector(Of T), ByVal v2 As DList(Of T)) As Boolean
            Return mismatch(v1.Begin, v1.End, v2.Begin, v2.End)
        End Function
        Public Shared Function mismatch(Of T As IComparable(Of T))(ByVal v1 As System.Collections.Generic.IList(Of T), ByVal v2 As System.Collections.Generic.IList(Of T)) As Boolean
            Return mismatch(NstlUtil.Begin(v1), NstlUtil.End(v1), NstlUtil.Begin(v2), NstlUtil.End(v2))
        End Function
        Public Shared Function mismatch(Of T As IComparable(Of T))(ByVal s As UniqueSet(Of T), ByVal l As System.Collections.Generic.IList(Of T)) As Boolean
            Dim v As New Vector(Of T)(s.Begin, s.End())
            Return mismatch(v, l)
        End Function

        Public Shared Function mismatch(Of T As IComparable(Of T))(ByVal v1 As System.Collections.Generic.IList(Of T), ByVal ParamArray v2 As T()) As Boolean
            Return mismatch(NstlUtil.Begin(v1), NstlUtil.End(v1), NstlUtil.Begin(v2), NstlUtil.End(v2))
        End Function
        Public Shared Function mismatch(Of T As IComparable(Of T))(ByVal v1 As MultiSet(Of T), ByVal ParamArray v2 As T()) As Boolean
            Return mismatch(v1.Begin, v1.End, NstlUtil.Begin(v2), NstlUtil.End(v2))
        End Function
        Public Shared Function equal(Of T As IComparable(Of T))(ByVal v1 As MultiSet(Of T), ByVal ParamArray v2 As T()) As Boolean
            Return Not mismatch(v1.Begin, v1.End, NstlUtil.Begin(v2), NstlUtil.End(v2))
        End Function

        Public Shared Function mismatch(Of T As IComparable(Of T))(ByVal l As DList(Of T), ByVal c As System.Collections.Generic.IList(Of T)) As Boolean
            Return mismatch(CType(l.ToArray(), System.Collections.Generic.IList(Of T)), c)
        End Function
        Public Shared Function mismatch(Of T As IComparable(Of T))(ByVal v1 As DList(Of T), ByVal ParamArray v2 As T()) As Boolean
            Return mismatch(v1.Begin, v1.End, NstlUtil.Begin(v2), NstlUtil.End(v2))
        End Function

        Public Shared Function equal(Of T As IComparable(Of T))(ByVal l As DList(Of T), ByVal v2 As Vector(Of T)) As Boolean
            Return Not mismatch(l, v2)
        End Function
        Public Shared Function equal(Of T As IComparable(Of T))(ByVal l As Vector(Of T), ByVal v2 As DList(Of T)) As Boolean
            Return Not mismatch(l, v2)
        End Function
        Public Shared Function equal(Of T As IComparable(Of T))(ByVal l As DList(Of T), ByVal ParamArray v2 As T()) As Boolean
            Return Not mismatch(l, v2)
        End Function
        Public Shared Function equal(Of T As IComparable(Of T))(ByVal l As DList(Of T), ByVal l2 As DList(Of T)) As Boolean
            Return Not mismatch(l.Begin, l.End, l2.Begin, l2.End)
        End Function
        Public Shared Function equal(Of T As IComparable(Of T))(ByVal _First1 As IForwardIterator(Of T), ByVal _Last1 As IForwardIterator(Of T), ByVal _First2 As IForwardIterator(Of T), ByVal _Last2 As IForwardIterator(Of T)) As Boolean
            Return Algorithm.Equal(_First1, _Last1, _First2, Compare.EqualTo(Of T)())
        End Function
        Public Shared Function equal(Of T As IComparable(Of T))(ByVal v1 As Vector(Of T), ByVal v2 As Vector(Of T)) As Boolean
            Return equal(v1.Begin, v1.End, v2.Begin, v2.End)
        End Function
        Public Shared Function equal(Of T As IComparable(Of T))(ByVal v1 As System.Collections.Generic.IList(Of T), ByVal v2 As System.Collections.Generic.IList(Of T)) As Boolean
            Return equal(NstlUtil.begin(v1), NstlUtil.end(v1), NstlUtil.begin(v2), NstlUtil.end(v2))
        End Function
        Public Shared Function equal(Of T As IComparable(Of T))(ByVal v1 As System.Collections.Generic.IList(Of T), ByVal ParamArray v2 As T()) As Boolean
            Return equal(NstlUtil.begin(v1), NstlUtil.end(v1), NstlUtil.begin(v2), NstlUtil.end(v2))
        End Function
        Public Shared Function equal(Of T As IComparable(Of T))(ByVal s As UniqueSet(Of T), ByVal l As System.Collections.Generic.IList(Of T)) As Boolean
            Dim v As New Vector(Of T)(s.Begin, s.End())
            Return equal(v, l)
        End Function
        Public Shared Function equal(Of T As IComparable(Of T))(ByVal _First1 As IForwardIterator(Of T), ByVal _Last1 As IForwardIterator(Of T), ByVal l As System.Collections.Generic.IList(Of T)) As Boolean
            Return equal(_First1, _Last1, NstlUtil.Begin(l), NstlUtil.End(l))
        End Function


        Public Shared Function mismatch(Of Key As IComparable(Of Key), Value As IComparable(Of Value))(ByVal m As map(Of Key, Value), ByVal keys As vector(Of Key), ByVal vals As vector(Of Value)) As Boolean
            Dim k As New vector(Of Key)
            Dim v As New vector(Of Value)
            Algorithm.Transform(m.Begin(), m.End(), NStlUtil.BackInserter(k), [Select].FirstFromKeyValuePair(Of Key, Value)())
            Algorithm.Transform(m.Begin(), m.End(), NStlUtil.BackInserter(v), [Select].SecondFromKeyValuePair(Of Key, Value)())
            Return mismatch(k, keys) Or mismatch(v, vals)
        End Function
        Public Shared Function mismatch(Of Key As IComparable(Of Key), Value As IComparable(Of Value))(ByVal m As map(Of Key, Value), ByVal keys As IList, ByVal vals As IList) As Boolean
            Return mismatch(m, New vector(Of Key)(keys), New vector(Of Value)(vals))
        End Function
        Public Shared Function equal(Of Key As IComparable(Of Key), Value As IComparable(Of Value))(ByVal m As map(Of Key, Value), ByVal keys As vector(Of Key), ByVal vals As vector(Of Value)) As Boolean
            Return Not mismatch(m, keys, vals)
        End Function
        Public Shared Function equal(Of Key As IComparable(Of Key), Value As IComparable(Of Value))(ByVal m As map(Of Key, Value), ByVal keys As IList, ByVal vals As IList) As Boolean
            Return Not mismatch(m, keys, vals)
        End Function


        Public Shared Function mismatch(Of Key As IComparable(Of Key), Value As IComparable(Of Value))(ByVal m As multimap(Of Key, Value), ByVal keys As vector(Of Key), ByVal vals As vector(Of Value)) As Boolean
            Dim k As New vector(Of Key)
            Dim v As New vector(Of Value)
            Algorithm.Transform(m.Begin(), m.End(), NStlUtil.BackInserter(k), [Select].FirstFromKeyValuePair(Of Key, Value)())
            Algorithm.Transform(m.Begin(), m.End(), NStlUtil.BackInserter(v), [Select].SecondFromKeyValuePair(Of Key, Value)())
            Return mismatch(k, keys) Or mismatch(v, vals)
        End Function
        Public Shared Function mismatch(Of Key As IComparable(Of Key), Value As IComparable(Of Value))(ByVal m As multimap(Of Key, Value), ByVal keys As IList, ByVal vals As IList) As Boolean
            Return mismatch(m, New vector(Of Key)(keys), New vector(Of Value)(vals))
        End Function
        Public Shared Function equal(Of Key As IComparable(Of Key), Value As IComparable(Of Value))(ByVal m As multimap(Of Key, Value), ByVal keys As IList, ByVal vals As IList) As Boolean
            Return Not mismatch(m, New vector(Of Key)(keys), New vector(Of Value)(vals))
        End Function
    End Class

    Friend Class IntGenerator
        Implements INullaryFunction(Of Integer)

        Private i As Integer = 0

        Public Function execute() As Integer Implements INullaryFunction(Of Integer).Execute
            Dim ii As Integer = i
            i += 1
            Return ii
        End Function
    End Class

    Friend Class mod_int
        Implements IBinaryFunction(Of Integer, Integer, Integer)

        Public Function execute(ByVal lhs As Integer, ByVal rhs As Integer) As Integer Implements IBinaryFunction(Of Integer, Integer, Integer).execute
            Return lhs Mod rhs
        End Function
    End Class
    Friend Class abs_mod_equal
        Implements IBinaryFunction(Of Integer, Integer, Boolean)

        Public Function execute(ByVal lhs As Integer, ByVal rhs As Integer) As Boolean Implements IBinaryFunction(Of Integer, Integer, Boolean).execute
            Return Math.Abs(lhs) = Math.Abs(rhs)
        End Function
    End Class

    Friend Class plus_int
        Implements IBinaryFunction(Of Integer, Integer, Integer)

        Public Function execute(ByVal lhs As Integer, ByVal rhs As Integer) As Integer Implements IBinaryFunction(Of Integer, Integer, Integer).execute
            Return lhs + rhs
        End Function
    End Class
    Friend Class minus_int
        Implements IBinaryFunction(Of Integer, Integer, Integer)

        Public Function execute(ByVal lhs As Integer, ByVal rhs As Integer) As Integer Implements IBinaryFunction(Of Integer, Integer, Integer).execute
            Return lhs - rhs
        End Function
    End Class

    Friend Class multiplies_int
        Implements IBinaryFunction(Of Integer, Integer, Integer)

        Public Function execute(ByVal lhs As Integer, ByVal rhs As Integer) As Integer Implements IBinaryFunction(Of Integer, Integer, Integer).Execute
            Return lhs * rhs
        End Function
    End Class

    Friend Class Vec2Map
        Implements IUnaryFunction(Of Integer, System.Collections.Generic.KeyValuePair(Of Integer, String))

        Public Function execute(ByVal par As Integer) As System.Collections.Generic.KeyValuePair(Of Integer, String) Implements IUnaryFunction(Of Integer, System.Collections.Generic.KeyValuePair(Of Integer, String)).Execute
            Return New System.Collections.Generic.KeyValuePair(Of Integer, String)(par, par.ToString())
        End Function
    End Class
End Namespace

